#ifndef CHATWIDGET_H
#define CHATWIDGET_H

#include <QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QListWidget>
#include <QTextEdit>
#include <QPushButton>
#include <QLabel>
#include <QSplitter>
#include "ChatClient.h"
#include "MessageWidget.h"

class ChatWidget : public QWidget
{
    Q_OBJECT

public:
    explicit ChatWidget(QWidget* parent = nullptr);
    ~ChatWidget();

public slots:
    void onLoginSuccess(const model::UserInfo& userInfo);
    void onMessageReceived(const model::Message& message);
    void onConnectionStatusChanged(bool connected);

private slots:
    void onSendMessage();
    void onConnectionError(const QString& error);

private:
    void setupUI();
    void setupConnections();
    void addMessageToChat(const model::Message& message);

    ChatClient* m_client;
    model::UserInfo m_currentUser;

    // UI组件[citation:6]
    QListWidget* m_onlineUsersList;
    QListWidget* m_chatHistoryList;
    QTextEdit* m_messageEdit;
    QPushButton* m_sendButton;
    QLabel* m_statusLabel;
};

#endif // CHATWIDGET_H

